class Ruiqu::CustomProductsController < Ruiqu::BaseController
  before_action :set_product, only: [:unuse, :edit, :update, :show]
  def index
    search_params
    @q = current_store.products.includes(:store_customer).customs.useable.ransack(params[:q])
    @store_products = @q.result.order("id desc")
  end

  def unuse
    @product.unuse!
    redirect_to ruiqu_custom_products_path
  end

  def edit

  end

  def update
    @product.update!(store_product_params.except(:images_attributes))
    redirect_to ruiqu_custom_products_path
  end

  def show

  end

  private
  def search_params
    params[:q] ||= {}
    @id = params[:q][:id_eq]
  end

  def set_product
    @product = StoreProduct.find(params[:id])
  end

  def store_product_params
    params.require(:store_product).permit(
                                      :name,
                                      :price,
                                      :vip_price,
                                      :vipable,
                                      :showable,
                                      :useable,
                                      :introduce,
                                      :format,
                                      :store_product_category_id,
                                      images_attributes: [
                                        :image
                                      ]
                                    )
  end

end
